package club.ximeng.sliceupload.upload.dto;

import cn.hutool.core.io.FileUtil;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;

/**
 * @author liu xm
 * @date 2022-03-08 9:57
 */
@Data
public class VerifyParamDTO implements Serializable {
    /**
     * 文件名称
     */
    @NotBlank(message = "文件名称不能为空")
    private String fileName;
    /**
     * 文件hash
     */
    @Length(min = 32, max = 32, message = "文件hash不正确")
    @NotBlank(message = "文件hash不能为空")
    String fileHash;

    /**
     * 带后缀的hash文件名
     */
    public String fullFileName() {
        return fileHash + "." + fileSuffix();
    }

    public String fileSuffix() {
        return FileUtil.getSuffix(fileName);
    }
}
